const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');

Page({
	data: {
		userInfo: {
			avatar: '/image/headimg.png',
			realname: '刘小凤'
		},
		chooseid: 1,
		attendNum: 0,
		attendList: []
	},
	onLoad(options) {
		this.toToday();
		var userInfo = app.globalData.userInfo;

		this.setData({
			userInfo: userInfo
		});
		this.getList();
		this.getAttendCount();
	},
	getAttendCount() {
		var that = this;
		http.httpPost(config.getAttendCount, {}, function(e) {
			if (e.code == 1) {
				that.setData({
					attendNum: e.data
				});
			}
		});
	},
	getList() {
		var that = this;
		http.httpPost(config.attendList, {
			type: that.data.chooseid
		}, function(e) {
			if (e.code == 1) {
				that.setData({
					attendList: e.data
				});
				// console.log(that.data.attendList);
			}
		});
	},
	toToday() {
		let year = new Date().getFullYear(),
			month = new Date().getMonth() + 1,
			day = new Date().getDate();
		if (month <= 9) {
			month = '0' + month;
		}
		if (day <= 9) {
			day = '0' + day;
		}

		this.setData({
			year,
			day,
			month
		})
	},
	choose(e) {
		this.setData({
			chooseid: e.currentTarget.dataset.id
		});
		this.getList();
	},
	onReady() {
		if (!app.login()) {
			return;
		}
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
